<?php
class EditAction extends CAction{
	
	public function run(){
		$model = $this->getController()->loadAdModel();
		if($model->status!==Ad::STATUS_PENDING && isset($_POST['AdsForm']))
		{
			$this->unsetPara();
			$form = $model->details;
			$form->attributes = $_POST['AdsForm'];
			$model->details = $form;
			if($form->redefineParams() && $form->validate() && $model->update('details')){
				$this->getController()->redirect(Yii::app()->createUrl('adv/ad',array('ad_id'=>$model->id)));
			}
		}
		$this->getController()->render('edit',array('model'=>$model->details,'status'=>$model->status));
	}

	public function unsetPara(){
		unset($_POST['AdsForm']['title'],
			  $_POST['AdsForm']['link'],
			  $_POST['AdsForm']['description'],
			  $_POST['AdsForm']['image'],
			  $_POST['AdsForm']['uploadImage'],
			  $_POST['AdsForm']['x'],
			  $_POST['AdsForm']['y'],
			  $_POST['AdsForm']['w'],
			  $_POST['AdsForm']['h'],
			  $_POST['AdsForm']['noImage'],
			  $_POST['AdsForm']['newImage']);
	}
}